public class A02_SelectionDemo02 {
    public static void main(String[] args) {
        //选择排序
        int[] arr = {5, 4, 3, 2, 1};
        //表示用哪一个索引与哪一个进行比较
        for (int i = 0; i < arr.length - 1; i++) {
            //拿着i和i后面的值进行比较
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[i] > arr[j]) {
                    int tmp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = tmp;
                }
            }
        }

        printArr(arr);
    }


    private static void printArr(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
    }
}
